// 蜂窝蜜造平台生成代码，此文件只生成一次，不需要添加到 .beeignore

package com.fowo.api.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.fowo.api.entity.RawMaterials;
import com.fowo.api.model.raw.materials.RawMaterialsVo;
import com.fowo.api.user.model.JwtUserInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import java.util.Date;
import java.util.Objects;

/**
 * 原材料管理 服务实现类
 */
@Service
public class RawMaterialsServiceImpl extends RawMaterialsBaseServiceImpl {

    /**
     * 更新所有子表
     * @param model 原材料管理
     */
    protected void updateAllChilds(RawMaterialsVo model) throws Exception {
        if (model.getProductSupplierQuote() != null) {
            productSupplierQuoteService.saveAllByParentProduct(
                    model.getId(),
                    model.getProductSupplierQuote()
            );
        }

        if (model.getIngredients() != null) {
            productIngredientsService.saveAllByProductId(
                    model.getId(),
                    model.getIngredients()
            );
        }

        if (model.getPacks() != null) {
            productPackService.saveAllByProductId(model.getId(), model.getPacks());
        }

        if (model.getCustoms() != null) {
            productCustomsPriceService.saveAllByProductId(
                    model.getId(),
                    model.getCustoms()
            );
        }

        if (model.getChecks() != null) {
            productQualityCheckService.saveAllByProductId(
                    model.getId(),
                    model.getChecks()
            );
        }

    }

}
